package com.example.performance.r2dbc.utils;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author zpMeng
 * @since 6/30/2025
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TestSuite {

    public static Map<Long, Integer> prepareSerialTestSuite() {
        Map<Long, Integer> nodeSizeToCount = new TreeMap<>();

/*        nodeSizeToCount.put(1L, 100);
        nodeSizeToCount.put(10L, 100);
        nodeSizeToCount.put(100L, 100);
        nodeSizeToCount.put(1000L, 20);
        nodeSizeToCount.put(10000L, 3);
        nodeSizeToCount.put(20000L, 3);*/
        nodeSizeToCount.put(1L, 1);
       // nodeSizeToCount.put(100000L, 1);

        return nodeSizeToCount;
    }

    public static Map<Integer, Integer> prepareParallelTestSuite(int start, int end, int nodeSize) {
        Map<Integer, Integer> concurrencyCountMap = new TreeMap<>();

        List<Integer> concurrencyInterval = defineConcurrencyInterval(start, end);

        switch (nodeSize) {
            case 100, 1000, 10000 -> {
                for (Integer concurrency : concurrencyInterval) {
                    int count = 10 / concurrency;
                    count = Math.max(count, 1);
                    concurrencyCountMap.put(concurrency, count);
                }
            }
            default -> {
            }
        }

        return concurrencyCountMap;
    }

    private static List<Integer> defineConcurrencyInterval(int start, int end) {
        int interval = 5;
        int actualStart = interval * (start / interval);
        int actualEnd = (end / interval) * interval;
        if (end % interval != 0) {
            actualEnd += interval;
        }

        ArrayList<Integer> result = new ArrayList<>();
        for (int i = actualStart; i <= actualEnd; i += interval) {
            result.add(i);
        }
        if (result.get(0).equals(0)) {
            result.set(0, 1);
        }
        return result;
    }

    public static Map<Integer, Integer> prepareParallelTestSuiteFor100() {
        return Map.of(20, 100);
    }

    public static void main(String[] args) {
        List<Integer> a = defineConcurrencyInterval(1, 20);
        System.out.println(a);
    }

}
